import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:series_play/comm/base/app_controller.dart';
import 'package:series_play/comm/base/base_state.dart';
import 'package:series_play/comm/base/user_manager.dart';
import 'package:series_play/comm/ext/context_ext.dart';
import 'package:series_play/net/api/account_api.dart';
import 'package:series_play/route/route_path.dart';
import 'package:series_play/utils/log.dart';
import 'package:series_play/widget/app_text.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends BaseState<SplashPage> {
  @override
  void initState() {
    super.initState();
    // 日志测试
    Log.init();
    checkLogin();
  }

  void checkLogin() async {
    final token = await UserManager.getToken();
    if (token.isEmpty) {
      // 未登录 启动游客登录
      final success = await UserManager.guestLogin();
      if (success) {
        Get.offNamed(RoutePath.main);
      }
    } else {
      Get.offNamed(RoutePath.main);
    }
  }

  @override
  bool hideAppbar() {
    return true;
  }

  @override
  Widget buildPage(BuildContext context) {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20).r,
              gradient: const LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [Color(0xffd90f52), Color(0xfff99917)],
              ),
            ),
            width: 72.w,
            height: 72.w,
            child: Center(),
          ),
          40.verticalSpace,
          ShaderMask(
            shaderCallback: (bounds) {
              return const LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [
                  Color(0xffd90f52),
                  Color(0xfff99917),
                  Color(0xffd90f52),
                ],
              ).createShader(bounds);
            },
            blendMode: BlendMode.srcIn,
            child: AppText(context.tr.splashWelcomeTip, fontSize: 14),
          ),
        ],
      ),
    );
  }
}
